<?php

namespace app\api\controller\msg;

use app\api\controller\Common;
class Lists extends Common
{
    protected $data;
    public function initialize()
    {
//        $this->checkUserLogin(); // 验证登录
        $this->data = $this->request->except(['sign','accessKey','token']);
    }

    /**
     * 温馨提示list - 分页数据
     */
    public function notice(){
        $page = $this->data['page'] ? $this->data['page'] : 1;
        $pageSize = $this->data['limit'] ? $this->data['limit'] : 20;
        $where = ['del'=>0];
        $paginate = ['list_rows'=>$pageSize,'page'=>$page];
        $list = db('lj_notice')
            ->field('id,title,top,important,create_time,update_time')
            ->where($where)->paginate($paginate)->toArray();
        if($list){
            $return = [
                'page' => $page,
                'pageNum' => $list['current_page'],
                'limit' => $pageSize,
                'total' => $list['total'],
                'list' => $list['data']
            ];
            $this->return = ['status'=>200,'code'=>'SUCCESS','message'=>'成功','data'=>$return];
        }else{
            $this->return = ['status'=>200,'code'=>'NOTICE_LIST_ERROR','message'=>'无数据'];
        }
        return $this->show($this->return);
    }

    /**
     * 温馨提示详情
     */
    public function noticeDetail(){
        $id = $this->data['id'];
        $info = db('lj_notice')->where('id',$id)->find();
        if($info){
            $this->return = ['status'=>200,'code'=>'SUCCESS','message'=>'成功','data'=>$info];
        }else{
            $this->return = ['status'=>200,'code'=>'NOTICE_DETAIL_ERROR','message'=>'无数据'];
        }
        return $this->show($this->return);
    }

    /**
     * 心动列表
     * type 1 我对谁 2 谁对我
     */
    public function heart(){
        $uid = $this->data['uid'];
        $type = $this->data['type'];
        $info = "";
        if($type == 1){
            $where = [
                'h.uid' => $uid,
                'h.del' => 0,
                'h.cannel' => 0
            ];
            $info = db('lj_heart')->alias('h')
                ->join('lj_users u','u.id = h.heart_uid')
                ->join('lj_users_baseinfo b','b.uid = h.heart_uid')
                ->where($where)
                ->select();
        }
        if($type == 2){
            $users = db('lj_users')->where('id',$uid)->find();
            if($users['vip'] == 0){
                $this->return = ['status'=>200,'code'=>'VIP_NO_ERROR','message'=>'只有VIP才可以看哦~'];
                return $this->show($this->return);
            }
            $where = [
                'h.heart_uid' => $uid,
                'h.del' => 0,
                'h.cannel' => 0
            ];
            $info = db('lj_heart')->alias('h')
                ->join('lj_users u','u.id = h.uid')
                ->join('lj_users_baseinfo b','b.uid = h.uid')
                ->where($where)
                ->select();
        }
        if($info){
            $this->return = ['status'=>200,'code'=>'SUCCESS','message'=>'成功','data'=>$info];
        }else{
            $this->return = ['status'=>200,'code'=>'HEART_LIST_ERROR','message'=>'无数据'];
        }
        return $this->show($this->return);
    }
}